package archer.student.model.form

import scala.util.Try

case class LoginValidateCode(currentMillions: Long, code: String) {

  def toCookieString: String = {
    s"${code}|${currentMillions}"
  }
}

object LoginValidateCode {

  def fromString(info: String): Option[LoginValidateCode] = {
    Try {
      val codeList = info.split('|').toList
      val randomCode :: millions :: Nil = codeList
      LoginValidateCode(currentMillions = millions.toLong, code = randomCode)
    }.toOption
  }

  val signinVerifyCode = "student-signin-verify-code"
  val signupVerifyCode = "signup-verify-code"
  val backSigninVerifyCode = "back-signin-verify-code"
  val retrievePassVerifyCode = "retrieve-pass-verify-code"

}
